﻿using System;

namespace Gmantis.Controls.DataGrid
{
    public class DataGridMergingCellsEventArgs : EventArgs
    {
        // Fields
        internal DataGridViewport Viewport;

        // Methods
        internal DataGridMergingCellsEventArgs()
        {
        }

        public void Merge(DataGridCellsRange range)
        {
            int num;
            int num2;
            int num3;
            int num4;
            if (!range.IsValid)
            {
                throw new ArgumentException("The specified range is not valid.");
            }
            if (this.Viewport.VisibleRange(range, out num, out num2, out num3, out num4))
            {
                for (int i = num; i <= num3; i++)
                {
                    for (int j = num2; j <= num4; j++)
                    {
                        DataGridCellPresenter presenter = this.Viewport.View.DataGrid[this.Viewport.Rows[j], this.Viewport.Columns[i]].Presenter;
                        DataGridCellsRange mergedRangeCandidate = presenter.MergedRangeCandidate;
                        Trace.Assert(mergedRangeCandidate.TopLeftCell.Row == this.Viewport.VisibleRows.Items[j]);
                        Trace.Assert(mergedRangeCandidate.BottomRightCell.Row == this.Viewport.VisibleRows.Items[j]);
                        Trace.Assert(mergedRangeCandidate.TopLeftCell.Column == this.Viewport.VisibleColumns.Items[i]);
                        Trace.Assert(mergedRangeCandidate.BottomRightCell.Column == this.Viewport.VisibleColumns.Items[i]);
                        presenter.MergedRangeCandidate = range;
                    }
                }
            }
        }
    }
}
